package com.winsomely.leecode;

/**
 * 数字转换为十六进制数
 * 
 * @author liujiawei
 *
 */
public class ToHex {

	private static char[] data = "0123456789abcdef".toCharArray();

	// 4608 = 16 * 16 * 18
	public String toHex(int num) {
		String hex = "";
		int ys;
		do {
			ys = num % 16;
			num = num / 16;
			hex = data[ys] + hex;
		} while (num >= 16);

		return num == 0 ? hex : data[num] + hex;
	}

	public static void main(String[] args) {
		ToHex t = new ToHex();
		int num = 16777215;
		System.out.println(Integer.toString(num, 16));
		System.out.println(t.toHex(num));
	}

}
